package org.example.provider.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/msg")
public class MqSendController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 发送消息到默认交换机 + 指定 routingKey
    @GetMapping("/send")
    public String send(@RequestParam String routingKey,
                       @RequestParam String msg) {
        rabbitTemplate.convertAndSend("demo-exchange",routingKey, msg);
        return "ok";
    }
}